<!DOCTYPE html>
<html>
	<head>
		<title> 页面加载/退出事件；表单事件 </title>
		<meta charset="utf-8" />
	</head>
	<body>
        <form id="f1">
            <input type="text" id="username"/>
            <input type="password" id="pwd"/>
            <input type="submit" valus="登录" id="sub"/>
        </form>

        <input type="text" id="calculate"/>
        <button id="btn"></button>
	</body>
    <script>
        document.onload = function(){
            console.log("页面加载完成");
        }
        document.onunload = function(){
            console.log("页面关闭");
        }
        var f1 = document.getElementById("f1");
        var username = document.getElementById("username");
        var pwd = document.getElementById("pwd");
        var sub = document.getElementById("sub");
        username.onblur = function(){
            var val = username.value;
            if(val.length < 3){
                alert("用户名过短");
            }
        }
        f1.submit = function(){
            alert("表单提交");
        }
        
        var btn = document.getElementById("btn");
        var calculate = document.getElementById("calculate");
        //当点击按钮时，将文本框中运算式运算结果alert出来
        btn.onclick = function(){
            var result = eval(calculate.value);
            alert(calculate.value + "=" + result);
        }
    </script>
</html>